package com.enqualcomm.kids.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.enqualcomm.kids.R;

import common.utils.DensityUtil;

/**
 * Created by yinzhiqun on 2015/11/16.
 */
public class MonitorDialog extends Dialog {

    private View monitor_pb;
    private ImageView monitor_iv;
    private TextView monitor_tv;

    public MonitorDialog(Context context) {
        super(context);
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(R.layout.dialog_monitor);

        setDialogAttributes();
        initDialogView();
    }

    public void setDialogAttributes() {
        Window dialogWindow = getWindow();
        setCanceledOnTouchOutside(false);
        setCancelable(false);//监护时不允许关闭对话框

        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        DisplayMetrics dm = new DisplayMetrics();
        dialogWindow.getWindowManager().getDefaultDisplay().getMetrics(dm);

        lp.width = dm.widthPixels - DensityUtil.dip2px(getContext(), 30); // 宽度
        // lp.alpha = 0.9f; // 透明度

        dialogWindow.setAttributes(lp);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    public void initDialogView() {
        monitor_pb = findViewById(R.id.monitor_pb);
        monitor_iv = (ImageView) findViewById(R.id.monitor_iv);
        monitor_tv = (TextView) findViewById(R.id.monitor_tv);
    }


    public void setErrorMsg(int stringId) {
        monitor_pb.setVisibility(View.INVISIBLE);
        monitor_iv.setVisibility(View.VISIBLE);
        monitor_tv.setText(stringId);
    }

}
